<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.1.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/hexo/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/hexo/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/hexo/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/hexo/images/logo.svg" color="#222">

<link rel="stylesheet" href="/hexo/css/main.css">


<link rel="stylesheet" href="/hexo/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"youchen12138.gitee.io","root":"/hexo/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta property="og:type" content="website">
<meta property="og:title" content="幽辰的博客">
<meta property="og:url" content="https://youchen12138.gitee.io/hexo/page/9/index.html">
<meta property="og:site_name" content="幽辰的博客">
<meta property="og:locale" content="en_US">
<meta property="article:author" content="幽辰">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://youchen12138.gitee.io/hexo/page/9/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'en'
  };
</script>

  <title>幽辰的博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/hexo/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">幽辰的博客</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/hexo/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/hexo/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>Tags<span class="badge">23</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/hexo/categories/" rel="section"><i class="fa fa-th fa-fw"></i>Categories<span class="badge">14</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/hexo/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives<span class="badge">127</span></a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Dart-%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%EF%BC%88OOP%EF%BC%89/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Dart-%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%EF%BC%88OOP%EF%BC%89/" class="post-title-link" itemprop="url">Dart-面向对象（OOP）</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:20:46 / Modified: 16:21:32" itemprop="dateCreated datePublished" datetime="2020-08-26T16:20:46+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Dart/" itemprop="url" rel="index"><span itemprop="name">Dart</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>所有的类都继承自 Object</p>
<h2 id="构造方法"><a href="#构造方法" class="headerlink" title="构造方法"></a>构造方法</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;命名构造方法：[类名+.+方法名]</span><br><span class="line">&#x2F;&#x2F;使用命名构造方法为类实现多个构造方法</span><br><span class="line">Student.cover(Student stu) : super(stu.name, stu.age) &#123;</span><br><span class="line">    print(&#39;命名构造方法&#39;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;命名工厂构造方法：factory [类名+.+方法名]</span><br><span class="line">&#x2F;&#x2F;它可以有返回值，而且不需要将类的final变量作为参数，是提供一种灵活获取类对象的方式。</span><br><span class="line">factory Student.stu(Student stu) &#123;</span><br><span class="line">    return Student(stu._school, stu.name, stu.age,</span><br><span class="line">        city: stu.city, country: stu.country);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;&#x2F;工厂构造方法演示</span><br><span class="line">class Logger &#123;</span><br><span class="line">    static Logger _cache;</span><br><span class="line"></span><br><span class="line">    &#x2F;&#x2F;  工厂构造方法：</span><br><span class="line">    &#x2F;&#x2F;  不仅仅是构造方法，更是一种模式</span><br><span class="line">    &#x2F;&#x2F;  有时候为了返回一个之前已经创建的缓存对象，原始的构造方法已经不能满足要求</span><br><span class="line">    &#x2F;&#x2F;  那么可以使用工厂模式来定义构造方法</span><br><span class="line">    factory Logger() &#123;</span><br><span class="line">        if (_cache &#x3D;&#x3D; null) &#123;</span><br><span class="line">        _cache &#x3D; Logger._internal();</span><br><span class="line">        &#125;</span><br><span class="line">        return _cache;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    Logger._internal();</span><br><span class="line"></span><br><span class="line">    void log(String msg) &#123;</span><br><span class="line">        print(msg);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="set-和-get"><a href="#set-和-get" class="headerlink" title="set 和 get"></a>set 和 get</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 可以为私有字段设置getter来让外界获取到私有字段</span><br><span class="line">String get school &#x3D;&gt; _school;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 可以为私有字段设置setter来控制外界对私有字段的修改</span><br><span class="line">set school(String value)&#123;</span><br><span class="line">    _school &#x3D; value;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="static"><a href="#static" class="headerlink" title="static"></a>static</h2><ul>
<li><p>使用 static 关键字来实现类级别的变量和函数</p>
</li>
<li><p>静态成员不能访问非静态成员（ static 关键字修饰的成员 不能访问 非 static 关键字修饰的成员）</p>
</li>
<li><p>非静态成员可以访问静态成员</p>
</li>
<li><p>类中的常量是需要使用 static const 声明</p>
</li>
</ul>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Dart-Mixins/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Dart-Mixins/" class="post-title-link" itemprop="url">Dart-Mixins</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:19:02 / Modified: 16:20:18" itemprop="dateCreated datePublished" datetime="2020-08-26T16:19:02+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Dart/" itemprop="url" rel="index"><span itemprop="name">Dart</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>mixins 是在多个类层次结构中重用代码的一种方式</p>
<p>要使用mixins，在with关键字后面跟上一个或多个mixin的名字（用逗号分隔），并且with要用在extends关键字之后</p>
<p>mixins的特征：实现mixin，就创建一个继承 Object 类的子类（不能继承其他类），不声明任何构造方法，不调用super</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Dart-%E6%A6%82%E8%BF%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Dart-%E6%A6%82%E8%BF%B0/" class="post-title-link" itemprop="url">Dart-概述</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:18:19 / Modified: 16:18:41" itemprop="dateCreated datePublished" datetime="2020-08-26T16:18:19+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Dart/" itemprop="url" rel="index"><span itemprop="name">Dart</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <ul>
<li><p>强类型语言，静态类型</p>
<ul>
<li>java、C#等</li>
</ul>
</li>
<li><p>面向对象的语言，OOP</p>
<ul>
<li>Python、C++、Objective-c、java、Kotlin等</li>
</ul>
</li>
<li><p>JIT &amp; AOT</p>
<ul>
<li><p>JIT：即即时编译，开发期间，更快编译，更快的重载</p>
</li>
<li><p>AOT：事前编译，release 期间，更快更流畅</p>
</li>
</ul>
</li>
</ul>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Dart-%E5%B8%B8%E7%94%A8%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Dart-%E5%B8%B8%E7%94%A8%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/" class="post-title-link" itemprop="url">Dart-常用数据类型</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:17:13 / Modified: 16:17:57" itemprop="dateCreated datePublished" datetime="2020-08-26T16:17:13+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Dart/" itemprop="url" rel="index"><span itemprop="name">Dart</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="常用数据类型"><a href="#常用数据类型" class="headerlink" title="常用数据类型"></a>常用数据类型</h2><ol>
<li><p>数字</p>
<ul>
<li><p>num</p>
</li>
<li><p>int</p>
</li>
<li><p>double</p>
</li>
</ul>
</li>
<li><p>字符串（String）（用<code>&#123;&#125;</code>来计算字符串中变量的值）</p>
</li>
<li><p>布尔值（bool）</p>
</li>
<li><p>集合</p>
<ul>
<li><p>List</p>
</li>
<li><p>Map</p>
</li>
</ul>
</li>
</ol>
<h3 id="数字（Number）"><a href="#数字（Number）" class="headerlink" title="数字（Number）"></a>数字（Number）</h3><p>Number 类型包括以下两类：</p>
<ul>
<li><p>int：整形</p>
</li>
<li><p>double：浮点型</p>
</li>
</ul>
<p>int 和 double 都是 num 类型的子类。</p>
<p>num 类型包括的操作有：<code>+</code>、<code>-</code>、<code>*</code>、<code>/</code>以及位移操作<code>&gt;&gt;</code></p>
<p>num 类型包括的常用方法有：abs、ceil 和 floor</p>
<h4 id="API"><a href="#API" class="headerlink" title="API"></a>API</h4><ul>
<li><p>abs()：绝对值</p>
  <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">num1.abs();</span><br></pre></td></tr></table></figure>
</li>
<li><p>toInt()：将数值转换成 int 类型</p>
  <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">num1.toInt();</span><br></pre></td></tr></table></figure>
</li>
<li><p>toDouble</p>
</li>
</ul>
<h2 id="map"><a href="#map" class="headerlink" title="map"></a>map</h2><p>map 是将 key 和 value 相关联的对象，key 和 value 都可以是任何类型的对象，并且 key 是唯一的。如果 key 重复后面添加的 key 会替换前面的</p>
<h3 id="map初始化"><a href="#map初始化" class="headerlink" title="map初始化"></a>map初始化</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Map names&#x3D;&#123;&#39;xiaoming&#39;: &#39;小明&#39;, &#39;xiaohong&#39;: &#39;小红&#39;&#125;;</span><br></pre></td></tr></table></figure>

<h3 id="遍历"><a href="#遍历" class="headerlink" title="遍历"></a>遍历</h3><ul>
<li><p>forEach()</p>
</li>
<li><p>map()</p>
</li>
<li><p>for-in</p>
</li>
</ul>
<p>注意：遍历时，新增或删除key都会报错，只能修改key</p>
<h3 id="常用API"><a href="#常用API" class="headerlink" title="常用API"></a>常用API</h3><ul>
<li><p>keys：key的集合</p>
</li>
<li><p>values：value 的集合</p>
</li>
<li><p>remove(key)：删除一个 key</p>
</li>
<li><p>removeWhere()：根据条件批量删除</p>
</li>
<li><p>containsKey()：是否包含 key</p>
</li>
<li><p>containsValue()：是否包含 value 值</p>
</li>
<li><p>clear()：清空 map</p>
</li>
<li><p>isEmpty()</p>
</li>
<li><p>toList()/toSet()：将结果转换成列表或者集合</p>
</li>
</ul>
<h2 id="dynamic、var、Object三者的区别"><a href="#dynamic、var、Object三者的区别" class="headerlink" title="dynamic、var、Object三者的区别"></a>dynamic、var、Object三者的区别</h2><h3 id="dynamic"><a href="#dynamic" class="headerlink" title="dynamic"></a>dynamic</h3><p>在编译时并不会确定数据类型，只有在运行时根据赋值判断数据类型</p>
<h3 id="var"><a href="#var" class="headerlink" title="var"></a>var</h3><p>var声明的变量在赋值的那一刻，就已经决定了它是什么类型。一旦被定义不能被改变其类型</p>
<h3 id="Object"><a href="#Object" class="headerlink" title="Object"></a>Object</h3><p>Object 可以被赋值为任意类型，因为所有类型都派生自 Object</p>
<h2 id="List（数组）"><a href="#List（数组）" class="headerlink" title="List（数组）"></a>List（数组）</h2><h3 id="声明"><a href="#声明" class="headerlink" title="声明"></a>声明</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">var list1 &#x3D; List();&#x2F;&#x2F; 不限定长度，不限定类型，可添加任意类型的数据</span><br></pre></td></tr></table></figure>

<h3 id="常用方法"><a href="#常用方法" class="headerlink" title="常用方法"></a>常用方法</h3><ul>
<li><p>add()：添加一个元素到List末尾</p>
</li>
<li><p>addAll()：两个List合并</p>
</li>
<li><p>insert(index,element)：在指定index处插入值</p>
</li>
<li><p>insertAll(index,list)：在指定index处插入list 其余顺延</p>
</li>
<li><p>remove(obj)：删除具体的元素</p>
</li>
<li><p>removeAt(index)：删除索引位置元素</p>
</li>
</ul>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/CSS%E9%A2%9D%E5%A4%96%E7%9F%A5%E8%AF%86%E7%82%B9-%E8%BE%B9%E6%A1%86%E6%95%88%E6%9E%9C/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/CSS%E9%A2%9D%E5%A4%96%E7%9F%A5%E8%AF%86%E7%82%B9-%E8%BE%B9%E6%A1%86%E6%95%88%E6%9E%9C/" class="post-title-link" itemprop="url">CSS额外知识点--边框效果</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 14:39:15 / Modified: 14:48:49" itemprop="dateCreated datePublished" datetime="2020-08-26T14:39:15+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/CSS/" itemprop="url" rel="index"><span itemprop="name">CSS</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="圆角效果-border-radius"><a href="#圆角效果-border-radius" class="headerlink" title="圆角效果 border-radius"></a>圆角效果 border-radius</h2><p>border-radius是向元素添加圆角边框。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">使用方法：</span><br><span class="line">border-radius:10px;&#x2F;* 所有角都使用半径为10px的圆角 *&#x2F; </span><br><span class="line"></span><br><span class="line">border-radius: 5px 4px 3px 2px; &#x2F;* 四个半径值分别是左上角、右上角、右下角和左下角，顺时针 *&#x2F;</span><br></pre></td></tr></table></figure>

<p>不要以为<code>border-radius</code>的值只能用px单位，你还可以用百分比或者em，但兼容性目前还不太好。</p>
<h2 id="阴影-box-shadow"><a href="#阴影-box-shadow" class="headerlink" title="阴影 box-shadow"></a>阴影 box-shadow</h2><p><img src="https://upload-images.jianshu.io/upload_images/16731485-24447860643b6893.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">box-shadow是向盒子添加阴影。支持添加一个或者多个。</span><br><span class="line"></span><br><span class="line">很简单的一段代码，就实现了投影效果，酷毙了。我们来看下语法：</span><br><span class="line"></span><br><span class="line">box-shadow: X轴偏移量 Y轴偏移量 [阴影模糊半径] [阴影扩展半径] [阴影颜色] [投影方式];</span><br><span class="line"></span><br><span class="line">参数介绍：</span><br><span class="line"></span><br><span class="line">注意：inset 可以写在参数的第一个或最后一个，其它位置是无效的。</span><br></pre></td></tr></table></figure>

<h4 id="为元素设置外阴影："><a href="#为元素设置外阴影：" class="headerlink" title="为元素设置外阴影："></a>为元素设置外阴影：</h4><p>示例代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">.box_shadow&#123;</span><br><span class="line">  box-shadow:4px 2px 6px #333333; </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>效果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-68f0c534aa788174.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h4 id="为元素设置内阴影："><a href="#为元素设置内阴影：" class="headerlink" title="为元素设置内阴影："></a>为元素设置内阴影：</h4><p>示例代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">.box_shadow&#123;</span><br><span class="line">  box-shadow:4px 2px 6px #333333 inset; </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>效果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-c35c85db846af2d5.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h4 id="阴影模糊半径与阴影扩展半径的区别"><a href="#阴影模糊半径与阴影扩展半径的区别" class="headerlink" title="阴影模糊半径与阴影扩展半径的区别"></a><font color="red">阴影模糊半径</font>与<font color="red">阴影扩展半径</font>的区别</h4><p>阴影模糊半径：此参数可选，其值只能是为正值，如果其值为0时，表示阴影不具有模糊效果，其值越大阴影的边缘就越模糊；</p>
<p>阴影扩展半径：此参数可选，其值可以是正负值，如果值为正，则整个阴影都延展扩大，反之值为负值时，则缩小；</p>
<h4 id="X轴偏移量和Y轴偏移量值可以设置为负数"><a href="#X轴偏移量和Y轴偏移量值可以设置为负数" class="headerlink" title="X轴偏移量和Y轴偏移量值可以设置为负数"></a><font color="red">X轴偏移量</font>和<font color="red">Y轴偏移量值</font>可以设置为负数</h4><p>box-shadow: X轴偏移量 Y轴偏移量 [阴影模糊半径] [阴影扩展半径] [阴影颜色] [投影方式];</p>
<p>X轴偏移量为负数：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">boxshadow-outset&#123;</span><br><span class="line">    width:100px;</span><br><span class="line">    height:100px;</span><br><span class="line">    box-shadow:-4px 4px 6px #666;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>效果图：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-b4b27030086a2af8.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>Y轴偏移量为负数：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">.boxshadow-outset&#123;</span><br><span class="line">    width:100px;</span><br><span class="line">    height:100px;</span><br><span class="line">    box-shadow:4px -4px 6px #666;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>效果图：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-59092670d968ca30.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h2 id="为边框应用图片-border-image"><a href="#为边框应用图片-border-image" class="headerlink" title="为边框应用图片 border-image"></a>为边框应用图片 border-image</h2><p>顾名思义就是为边框应用背景图片，它和我们常用的background属性比较相似。例如：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">background:url(xx.jpg) 10px 20px no-repeat;</span><br></pre></td></tr></table></figure>

<p>但是又比背景图片复杂一些。</p>
<p>想象一下：一个矩形，有四个边框。如果应用了边框图片，图片该怎么分布呢？ 图片会自动被切割分成四等分。用于四个边框。</p>
<p>可以理解为它是一个切片工具，会自动把用做边框的图片切割。怎么切割呢？为了方便理解，做了一张特殊的图片，由9个矩形（70<code>*</code>70像素）拼成的一张图（210<code>*</code>210像素），并标注好序号，是不是像传说中的九宫图，如下：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-f66876c8924156f6.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>我们把上图当作边框图片 来应用一下， 看一看是什么效果</p>
<p>根据border-image的语法：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-0e4f1761de08cbe2.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">#border-image&#123;</span><br><span class="line">   background:#F4FFFA;</span><br><span class="line">   width:210px; height:210px; border:70px solid #ddd;</span><br><span class="line">   border-image:url(borderimg.png) 70 repeat  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>效果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-e63d308a1fda14b1.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>从序号可以看出div的四个角分别对应了背景图片的四个角。而2,4,6,8 被重复。5在哪？因为是从四周向中心切割图片的所以，5显示不出来。而在chrome浏览器中5是存在的，下图的样子：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-0791ed3706cf71e9.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><strong>repeat</strong>的意思就是重复，目前因为是刚好被整除，效果看不出来。如果改下DIV的宽高，再来看重复的效果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-a62ff9e7cf5322b8.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>边角部分为裁掉了，可见repeat就是一直重复，然后超出部分剪裁掉，而且是居中开始重复。</p>
<p><strong>Round 参数</strong>：Round可以理解为圆满的铺满。为了实现圆满所以会压缩（或拉伸）；</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">#border-image &#123;</span><br><span class="line"></span><br><span class="line">     width:170px;</span><br><span class="line"></span><br><span class="line">     height:170px;</span><br><span class="line"></span><br><span class="line">     border:70px solid;</span><br><span class="line"></span><br><span class="line">     border-image:url(borderimg.png) 70 round;</span><br><span class="line"></span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<p>效果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-7ec3778d80ce4b2a.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>可见图片被压扁了。</p>
<p><strong>Stretch</strong> 很好理解就是拉伸，有多长拉多长。有多远“滚”多远。</p>
<p><code>border-image:url(borderimg.png) 70 stretch</code></p>
<p>看一下效果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-04d201c63c5ba315.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>2,4,6,8分别被拉伸显示。</p>
<p>注意：Chrome下，中间部分也会被拉伸，webkit浏览器对于round属性和repeat属性似乎没有区分，显示效果是一样的。</p>
<p>Firefox 26.0 下是可以准确区分的。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/CSS%E9%A2%9D%E5%A4%96%E7%9F%A5%E8%AF%86%E7%82%B9-%E8%83%8C%E6%99%AF%E6%A0%B7%E5%BC%8F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/CSS%E9%A2%9D%E5%A4%96%E7%9F%A5%E8%AF%86%E7%82%B9-%E8%83%8C%E6%99%AF%E6%A0%B7%E5%BC%8F/" class="post-title-link" itemprop="url">CSS额外知识点--背景样式</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 14:38:31 / Modified: 14:38:46" itemprop="dateCreated datePublished" datetime="2020-08-26T14:38:31+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/CSS/" itemprop="url" rel="index"><span itemprop="name">CSS</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="background-origin"><a href="#background-origin" class="headerlink" title="background-origin"></a><strong>background-origin</strong></h2><p>设置元素背景图片的原始起始位置。</p>
<p>语法：</p>
<p><code>background-origin ： border-box | padding-box | content-box;</code></p>
<p>参数分别表示背景图片是从边框，还是内边距（默认值），或者是内容区域开始显示。</p>
<p>效果如下：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-c3735874e493a5ff.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>需要注意的是，如果背景不是no-repeat，这个属性无效，它会从边框开始显示。</p>
<h2 id="background-clip"><a href="#background-clip" class="headerlink" title="background-clip"></a><strong>background-clip</strong></h2><p>用来将背景图片做适当的裁剪以适应实际需要。</p>
<p>语法：</p>
<p><code>background-clip ： border-box | padding-box | content-box | no-clip</code></p>
<p>参数分别表示从<strong>边框</strong>、或<strong>内填充</strong>，或者<strong>内容区域向外裁剪背景</strong>。no-clip表示不裁切，和参数border-box显示同样的效果。backgroud-clip默认值为border-box。</p>
<p>效果如下图所示：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-26ffc59a115ff08d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h2 id="background-size"><a href="#background-size" class="headerlink" title="background-size"></a><strong>background-size</strong></h2><p>设置背景图片的大小，以<strong>长度值</strong>或<strong>百分比</strong>显示，还可以通过<strong>cover</strong>和<strong>contain</strong>来对图片进行伸缩。</p>
<p>语法：</p>
<p><code>background-size: auto | &lt;长度值&gt; | &lt;百分比&gt; | cover | contain</code></p>
<p>取值说明：</p>
<p>1、<strong>auto</strong>：默认值，不改变背景图片的原始高度和宽度；</p>
<p>2、**&lt;长度值&gt;**：成对出现如200px 50px，将背景图片宽高依次设置为前面两个值，当设置一个值时，将其作为图片宽度值来等比缩放；</p>
<p>3、**&lt;百分比&gt;**：0％~100％之间的任何值，将背景图片宽高依次设置为所在元素宽高乘以前面百分比得出的数值，当设置一个值时同上；</p>
<p>4、<strong>cover</strong>：顾名思义为覆盖，即将背景图片等比缩放以填满整个容器；</p>
<p>5、<strong>contain</strong>：容纳，即将背景图片等比缩放至某一边紧贴容器边缘为止。</p>
<h2 id="multiple-backgrounds"><a href="#multiple-backgrounds" class="headerlink" title="multiple backgrounds"></a><strong>multiple backgrounds</strong></h2><p>多重背景，也就是CSS2里<strong>background</strong>的属性外加<strong>origin</strong>、<strong>clip</strong>和<strong>size</strong>组成的新background的多次叠加，缩写时为用<strong>逗号</strong>隔开的每组值；用分解写法时，如果有多个背景图片，而其他属性只有一个（例如background-repeat只有一个），表明所有背景图片应用该属性值。</p>
<p>语法缩写如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">background ： [background-color] | [background-image] | [background-position][&#x2F;background-size] | [background-repeat] | [background-attachment] | [background-clip] | [background-origin],...</span><br></pre></td></tr></table></figure>

<p>可以把上面的缩写拆解成以下形式：</p>
<p><code>background-image:url1,url2,...,urlN;</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">background-repeat : repeat1,repeat2,...,repeatN;</span><br><span class="line">backround-position : position1,position2,...,positionN;</span><br><span class="line">background-size : size1,size2,...,sizeN;</span><br><span class="line">background-attachment : attachment1,attachment2,...,attachmentN;</span><br><span class="line">background-clip : clip1,clip2,...,clipN;</span><br><span class="line">background-origin : origin1,origin2,...,originN;</span><br><span class="line">background-color : color;</span><br></pre></td></tr></table></figure>

<p>注意：</p>
<p>用逗号隔开每组 background 的缩写值；</p>
<p>如果有 size 值，需要紧跟 position 并且用 “/“ 隔开；</p>
<p>如果有多个背景图片，而其他属性只有一个（例如 background-repeat 只有一个），表明所有背景图片应用该属性值。</p>
<p>background-color 只能设置一个。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/CSS%E9%A2%9D%E5%A4%96%E7%9F%A5%E8%AF%86%E7%82%B9-%E6%96%87%E5%AD%97%E5%92%8C%E5%AD%97%E4%BD%93/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/CSS%E9%A2%9D%E5%A4%96%E7%9F%A5%E8%AF%86%E7%82%B9-%E6%96%87%E5%AD%97%E5%92%8C%E5%AD%97%E4%BD%93/" class="post-title-link" itemprop="url">CSS额外知识点--文字和字体</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 14:37:39 / Modified: 14:38:05" itemprop="dateCreated datePublished" datetime="2020-08-26T14:37:39+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/CSS/" itemprop="url" rel="index"><span itemprop="name">CSS</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="text-overflow-与-word-wrap"><a href="#text-overflow-与-word-wrap" class="headerlink" title="text-overflow 与 word-wrap"></a><strong>text-overflow</strong> 与 <strong>word-wrap</strong></h2><p>text-overflow用来设置是否使用一个省略标记（…）标示对象内文本的溢出。</p>
<p>语法：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-ddd290865ca9af27.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>但是<strong>text-overflow</strong>只是用来说明文字溢出时用什么方式显示，要实现溢出时产生<strong>省略号</strong>的效果，还须定义<strong>强制文本在一行内显示</strong>（white-space:nowrap）及<strong>溢出内容为隐藏</strong>（overflow:hidden），只有这样才能实现<strong>溢出文本显示省略号</strong>的效果，代码如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">text-overflow:ellipsis; </span><br><span class="line">overflow:hidden; </span><br><span class="line">white-space:nowrap; </span><br></pre></td></tr></table></figure>

<p>同时，<strong>word-wrap</strong>也可以用来设置<strong>文本行为</strong>，当前行超过指定容器的边界时是否断开转行。</p>
<p>语法：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-c35f005b0f07468f.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><strong>normal</strong>为浏览器默认值，<strong>break-word</strong>设置在长单词或 <strong>URL地址</strong>内部进行换行，此属性不常用，用浏览器默认值即可。</p>
<h2 id="嵌入字体-font-face"><a href="#嵌入字体-font-face" class="headerlink" title="嵌入字体@font-face"></a><strong>嵌入字体@font-face</strong></h2><p>@font-face能够加载服务器端的字体文件，让浏览器端可以显示用户电脑里没有安装的字体。</p>
<p>语法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">@font-face &#123;</span><br><span class="line">    font-family : 字体名称;</span><br><span class="line">    src : 字体文件在服务器上的相对或绝对路径;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>这样设置之后，就可以像使用普通字体一样在<code>（font-*）</code>中设置字体样式。</p>
<p>比如：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">p &#123;</span><br><span class="line">    font-size :12px;</span><br><span class="line">    font-family : &quot;My Font&quot;;</span><br><span class="line">    &#x2F;*必须项，设置@font-face中font-family同样的值*&#x2F;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="文本阴影text-shadow"><a href="#文本阴影text-shadow" class="headerlink" title="文本阴影text-shadow"></a>文本阴影text-shadow</h2><p>text-shadow可以用来设置文本的阴影效果。</p>
<p>语法：</p>
<p><code>text-shadow: X-Offset Y-Offset blur color;</code></p>
<p><font color="LightPink">X-Offset</font>：表示阴影的水平偏移距离，其值为正值时阴影向右偏移，反之向左偏移；      </p>
<p><font color="LightPink">Y-Offset</font>：是指阴影的垂直偏移距离，如果其值是正值时，阴影向下偏移，反之向上偏移；</p>
<p><font color="LightPink">Blur</font>：是指阴影的模糊程度，其值不能是负值，如果值越大，阴影越模糊，反之阴影越清晰，如果不需要阴影模糊可以将Blur值设置为0；</p>
<p><font color="LightPink">Color</font>：是指阴影的颜色，其可以使用rgba色。</p>
<p>比如，我们可以用下面代码实现设置阴影效果。</p>
<p><code>text-shadow: 0 1px 1px #fff</code></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/CSS%E9%A2%9D%E5%A4%96%E7%9F%A5%E8%AF%86%E7%82%B9-%E9%80%89%E6%8B%A9%E5%99%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/CSS%E9%A2%9D%E5%A4%96%E7%9F%A5%E8%AF%86%E7%82%B9-%E9%80%89%E6%8B%A9%E5%99%A8/" class="post-title-link" itemprop="url">CSS额外知识点--选择器</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 14:36:51 / Modified: 14:37:16" itemprop="dateCreated datePublished" datetime="2020-08-26T14:36:51+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/CSS/" itemprop="url" rel="index"><span itemprop="name">CSS</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="属性选择器"><a href="#属性选择器" class="headerlink" title="属性选择器"></a>属性选择器</h2><p>在HTML中，通过各种各样的属性可以给元素增加很多附加的信息。例如，通过id属性可以将不同div元素进行区分。</p>
<p>在CSS2中引入了一些属性选择器，而CSS3在CSS2的基础上对属性选择器进行了扩展，新增了3个属性选择器，使得属性选择器有了通配符的概念，这三个属性选择器与CSS2的属性选择器共同构成了CSS功能强大的属性选择器。如下表所示：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-4376cdb6899a8289.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h3 id="实例展示："><a href="#实例展示：" class="headerlink" title="实例展示："></a>实例展示：</h3><p>html代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;a href&#x3D;&quot;xxx.pdf&quot;&gt;我链接的是PDF文件&lt;&#x2F;a&gt;</span><br><span class="line">&lt;a href&#x3D;&quot;#&quot; class&#x3D;&quot;icon&quot;&gt;我类名是icon&lt;&#x2F;a&gt;</span><br><span class="line">&lt;a href&#x3D;&quot;#&quot; title&#x3D;&quot;我的title是more&quot;&gt;我的title是more&lt;&#x2F;a&gt;</span><br></pre></td></tr></table></figure>

<p>css代码  </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">a[class^&#x3D;icon]&#123;</span><br><span class="line">  background: green;</span><br><span class="line">  color:#fff;</span><br><span class="line">&#125;</span><br><span class="line">a[href$&#x3D;pdf]&#123;</span><br><span class="line">  background: orange;</span><br><span class="line">  color: #fff;</span><br><span class="line">&#125;</span><br><span class="line">a[title*&#x3D;more]&#123;</span><br><span class="line">  background: blue;</span><br><span class="line">  color: #fff;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p> 结果显示：</p>
<p> <img src="https://upload-images.jianshu.io/upload_images/16731485-f064c250e1e7da27.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h2 id="结构性伪类选择器—root"><a href="#结构性伪类选择器—root" class="headerlink" title="结构性伪类选择器—root"></a>结构性伪类选择器—root</h2><p><code>:root</code>选择器，从字面上我们就可以很清楚的理解是<font color="red">根选择器</font>，他的意思就是匹配元素E所在文档的<font color="red">根元素</font>。在HTML文档中，根元素始终是<font color="red"><code>&lt;html&gt;</code></font>。</p>
<p>示例演示：</p>
<p>通过“:root”选择器设置背景颜色</p>
<p>HTML代码：</p>
<p><code>&lt;div&gt;:root选择器的演示&lt;/div&gt;</code></p>
<p>CSS代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">:root &#123;</span><br><span class="line">  background:orange;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>演示结果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-d090efe9c42b634e.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>“:root”选择器等同于<html>元素，简单点说：</p>
<p><code>:root&#123;background:orange&#125;</code></p>
<p><code>html &#123;background:orange;&#125;</code></p>
<p>得到的效果等同。</p>
<p>建议使用:root方法。</p>
<p>另外在IE9以下还可以借助“:root”实现hack功能。</p>
<h2 id="结构性伪类选择器—not"><a href="#结构性伪类选择器—not" class="headerlink" title="结构性伪类选择器—not"></a>结构性伪类选择器—not</h2><p><code>:not</code>选择器称为<font color="red">否定选择器</font>，和jQuery中的:not选择器一模一样，可以选择除某个元素之外的所有元素。就拿form元素来说，比如说你想给表单中除submit按钮之外的input元素添加红色边框，CSS代码可以写成：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">form &#123;</span><br><span class="line">  width: 200px;</span><br><span class="line">  margin: 20px auto;</span><br><span class="line">&#125;</span><br><span class="line">div &#123;</span><br><span class="line">  margin-bottom: 20px;</span><br><span class="line">&#125;</span><br><span class="line">input:not([type&#x3D;&quot;submit&quot;])&#123;</span><br><span class="line">  border:1px solid red;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>相关HTML代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&lt;form action&#x3D;&quot;#&quot;&gt;</span><br><span class="line">  &lt;div&gt;</span><br><span class="line">    &lt;label for&#x3D;&quot;name&quot;&gt;Text Input:&lt;&#x2F;label&gt;</span><br><span class="line">    &lt;input type&#x3D;&quot;text&quot; name&#x3D;&quot;name&quot; id&#x3D;&quot;name&quot; placeholder&#x3D;&quot;John Smith&quot; &#x2F;&gt;</span><br><span class="line">  &lt;&#x2F;div&gt;</span><br><span class="line">  &lt;div&gt;</span><br><span class="line">    &lt;label for&#x3D;&quot;name&quot;&gt;Password Input:&lt;&#x2F;label&gt;</span><br><span class="line">    &lt;input type&#x3D;&quot;text&quot; name&#x3D;&quot;name&quot; id&#x3D;&quot;name&quot; placeholder&#x3D;&quot;John Smith&quot; &#x2F;&gt;</span><br><span class="line">  &lt;&#x2F;div&gt;</span><br><span class="line">  &lt;div&gt;</span><br><span class="line">    &lt;input type&#x3D;&quot;submit&quot; value&#x3D;&quot;Submit&quot; &#x2F;&gt;</span><br><span class="line">  &lt;&#x2F;div&gt;</span><br><span class="line">&lt;&#x2F;form&gt;  </span><br></pre></td></tr></table></figure>

<p>演示结果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-875aa28615ca7231.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h2 id="结构性伪类选择器—empty"><a href="#结构性伪类选择器—empty" class="headerlink" title="结构性伪类选择器—empty"></a>结构性伪类选择器—empty</h2><p><code>:empty</code>选择器表示的就是空。用来选择没有任何内容的元素，这里没有内容指的是一点内容都没有，<strong>哪怕是一个空格。</strong></p>
<p>示例显示：</p>
<p>比如说，你的文档中有三个段落p元素，你想把没有任何内容的P元素隐藏起来。我们就可以使用“:empty”选择器来控制。</p>
<p>HTML代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;p&gt;我是一个段落&lt;&#x2F;p&gt;</span><br><span class="line">&lt;p&gt; &lt;&#x2F;p&gt;</span><br><span class="line">&lt;p&gt;&lt;&#x2F;p&gt;</span><br></pre></td></tr></table></figure>

<p>CSS代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">p&#123;</span><br><span class="line"> background: orange;</span><br><span class="line"> min-height: 30px;</span><br><span class="line">&#125;</span><br><span class="line">p:empty &#123;</span><br><span class="line">  display: none;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>演示结果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-032a25c21171fc1a.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h2 id="结构性伪类选择器—target"><a href="#结构性伪类选择器—target" class="headerlink" title="结构性伪类选择器—target"></a>结构性伪类选择器—target</h2><p><code>:target</code>选择器称为目标选择器，用来匹配文档(页面)的<strong>url的某个标志符的目标元素</strong>。我们先来上个例子，然后再做分析。</p>
<p>示例展示</p>
<p>点击链接显示隐藏的段落。</p>
<p>HTML代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;h2&gt;&lt;a href&#x3D;&quot;#brand&quot;&gt;Brand&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;</span><br><span class="line">&lt;div class&#x3D;&quot;menuSection&quot; id&#x3D;&quot;brand&quot;&gt;</span><br><span class="line">    content for Brand</span><br><span class="line">&lt;&#x2F;div&gt;</span><br></pre></td></tr></table></figure>

<p>CSS代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">.menuSection&#123;</span><br><span class="line">  display: none;</span><br><span class="line">&#125;</span><br><span class="line">:target&#123;&#x2F;*这里的:target就是指id&#x3D;&quot;brand&quot;的div对象*&#x2F;</span><br><span class="line">  display:block;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>演示结果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-1450d217d1c8863e.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>分析：</p>
<ol>
<li><p>具体来说，触发元素的URL中的标志符通常会包含一个<font color="red">#号</font>，后面带有一个<font color="red">标志符名称</font>，上面代码中是：#brand</p>
</li>
<li><p><code>：target</code>就是用来匹配id为“brand”的元素（id=”brand”的元素）,上面代码中是那个div元素。</p>
</li>
</ol>
<p><strong>多个url（多个target）处理：</strong></p>
<p>就像上面的例子，#brand与后面的id=”brand”是对应的，当同一个页面上有很多的url的时候你可以取不同的名字，只要#号后对的名称与<font color="red">id=””</font>中的名称对应就可以了。<br>如下面例子：<br>html代码：  </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&lt;h2&gt;&lt;a href&#x3D;&quot;#brand&quot;&gt;Brand&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;</span><br><span class="line">&lt;div class&#x3D;&quot;menuSection&quot; id&#x3D;&quot;brand&quot;&gt;</span><br><span class="line">  content for Brand</span><br><span class="line">&lt;&#x2F;div&gt;</span><br><span class="line">&lt;h2&gt;&lt;a href&#x3D;&quot;#jake&quot;&gt;Brand&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;</span><br><span class="line">&lt;div class&#x3D;&quot;menuSection&quot; id&#x3D;&quot;jake&quot;&gt;</span><br><span class="line"> content for jake</span><br><span class="line">&lt;&#x2F;div&gt;</span><br><span class="line">&lt;h2&gt;&lt;a href&#x3D;&quot;#aron&quot;&gt;Brand&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;</span><br><span class="line">&lt;div class&#x3D;&quot;menuSection&quot; id&#x3D;&quot;aron&quot;&gt;</span><br><span class="line">    content for aron</span><br><span class="line">&lt;&#x2F;div&gt;</span><br></pre></td></tr></table></figure>

<p>css代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">#brand:target &#123;</span><br><span class="line">  background: orange;</span><br><span class="line">  color: #fff;</span><br><span class="line">&#125;</span><br><span class="line">#jake:target &#123;</span><br><span class="line">  background: blue;</span><br><span class="line">  color: #fff;</span><br><span class="line">&#125;</span><br><span class="line">#aron:target &#123;</span><br><span class="line">  background: red;</span><br><span class="line">  color: #fff;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>上面的代码可以对不同的target对象分别设置不的样式。</p>
<h2 id="结构性伪类选择器—first-child"><a href="#结构性伪类选择器—first-child" class="headerlink" title="结构性伪类选择器—first-child"></a>结构性伪类选择器—first-child</h2><p>“:first-child”选择器表示的是选择<strong>父元素的第一个子元素的元素E</strong>。简单点理解就是选择元素中的第一个<strong>子元素</strong>，记住是子元素，而不是后代元素。</p>
<p>示例演示</p>
<p>通过“:first-child”选择器定位列表中的第一个列表项，并将序列号颜色变为红色。</p>
<p>HTML代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;ol&gt;</span><br><span class="line">  &lt;li&gt;&lt;a href&#x3D;&quot;##&quot;&gt;Link1&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;&lt;a href&#x3D;&quot;##&quot;&gt;Link2&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;&lt;a href&#x3D;&quot;##&quot;&gt;link3&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;</span><br><span class="line">&lt;&#x2F;ol&gt;</span><br></pre></td></tr></table></figure>

<p>CSS代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">ol &gt; li&#123;</span><br><span class="line">  font-size:20px;</span><br><span class="line">  font-weight: bold;</span><br><span class="line">  margin-bottom: 10px;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">ol a &#123;</span><br><span class="line">  font-size: 16px;</span><br><span class="line">  font-weight: normal;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">ol &gt; li:first-child&#123;</span><br><span class="line">  color: red;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>演示结果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-f18a39994c2e8374.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h2 id="结构性伪类选择器—last-child"><a href="#结构性伪类选择器—last-child" class="headerlink" title="结构性伪类选择器—last-child"></a>结构性伪类选择器—last-child</h2><p>“:last-child”选择器与“:first-child”选择器作用类似，不同的是“:last-child”选择器选择的是元素的最后一个子元素。例如，需要改变的是列表中的最后一个“li”的背景色，就可以使用这个选择器，</p>
<p><code>ul&gt;li:last-child&#123;background:blue;&#125;</code></p>
<p>示例演示</p>
<p>在博客的排版中，每个段落都有15px的margin-bottom，假设不想让博客“post”中最后一个段落不需要底部的margin值，可以使用“:last-child”选择器。</p>
<p>HTML代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&lt;div class&#x3D;&quot;post&quot;&gt;</span><br><span class="line">  &lt;p&gt;第一段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;p&gt;第二段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;p&gt;第三段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;p&gt;第四段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;p&gt;第五段落&lt;&#x2F;p&gt;</span><br><span class="line">&lt;&#x2F;div&gt;</span><br></pre></td></tr></table></figure>

<p>CSS代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">.post &#123;</span><br><span class="line">  padding: 10px;</span><br><span class="line">  border: 1px solid #ccc;</span><br><span class="line">  width: 200px;</span><br><span class="line">  margin: 20px auto;</span><br><span class="line">&#125;</span><br><span class="line">.post p &#123;</span><br><span class="line">  margin:0 0 15px 0;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">.post p:last-child &#123;</span><br><span class="line">  margin-bottom:0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>演示结果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-1df83e58cb0f5e9a.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h2 id="结构性伪类选择器—nth-child-n"><a href="#结构性伪类选择器—nth-child-n" class="headerlink" title="结构性伪类选择器—nth-child(n)"></a>结构性伪类选择器—nth-child(n)</h2><p>“:nth-child(n)”选择器用来定位<strong>某个父元素的一个或多个特定的子元素</strong>。其中“n”是其参数，而且可以是整数值(1,2,3,4)，也可以是表达式(2n+1、-n+5)和关键词(odd、even)，但参数n的起始值始终是1，而不是0。也就是说，参数n的值为0时，选择器将选择不到任何匹配的元素。</p>
<p><strong>经验与技巧</strong>:当“:nth-child(n)”选择器中的n为一个表达式时，其中n是从0开始计算，当表达式的值为0或小于0的时候，不选择任何匹配的元素。如下表所示：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-d7dbdd48f161961f.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>案例演示</p>
<p>  通过“:nth-child(n)”选择器，并且参数使用表达式“2n”，将偶数行列表背景色设置为橙色。</p>
<p>HTML代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&lt;ol&gt;</span><br><span class="line">  &lt;li&gt;item1&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item2&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item3&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item4&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item5&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item6&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item7&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item8&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item9&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item10&lt;&#x2F;li&gt;</span><br><span class="line">&lt;&#x2F;ol&gt;</span><br></pre></td></tr></table></figure>

<p>CSS代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ol &gt; li:nth-child(2n)&#123;</span><br><span class="line">  background: orange;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>演示结果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-fa24984285fdd95c.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h2 id="结构性伪类选择器—nth-last-child-n"><a href="#结构性伪类选择器—nth-last-child-n" class="headerlink" title="结构性伪类选择器—nth-last-child(n)"></a>结构性伪类选择器—nth-last-child(n)</h2><p>“:nth-last-child(n)”选择器和前面的“:nth-child(n)”选择器非常的相似，只是这里多了一个“last”，所起的作用和“:nth-child(n)”选择器有所区别，从某父元素的最后一个子元素开始计算，来选择特定的元素。</p>
<p>案例演示</p>
<p>选择列表中<font color="red">倒数</font>第五个列表项，将其背景设置为橙色。</p>
<p>HTML代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">&lt;ol&gt;</span><br><span class="line">  &lt;li&gt;item1&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item2&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item3&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item4&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item5&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item6&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item7&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item8&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item9&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item10&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item11&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item12&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item13&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item14&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;li&gt;item15&lt;&#x2F;li&gt;</span><br><span class="line">&lt;&#x2F;ol&gt;</span><br></pre></td></tr></table></figure>

<p>CSS代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ol &gt; li:nth-last-child(5)&#123;</span><br><span class="line">  background: orange;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>演示结果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-8341d87883a888d4.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h2 id="first-of-type选择器"><a href="#first-of-type选择器" class="headerlink" title="first-of-type选择器"></a>first-of-type选择器</h2><p>“:first-of-type”选择器类似于“:first-child”选择器，不同之处就是指定了元素的类型,其主要用来定位一个父元素下的某个类型的第一个子元素。</p>
<p><strong>示例演示：</strong></p>
<p>通过“:first-of-type”选择器，定位div容器中的第一个p元素（p不一定是容器中的第一个子元素），并设置其背景色为橙色。</p>
<p>HTML代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&lt;div class&#x3D;&quot;wrapper&quot;&gt;</span><br><span class="line">  &lt;div&gt;我是一个块元素，我是.wrapper的第一个子元素&lt;&#x2F;div&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落元素，我是不是.wrapper的第一个子元素，但是他的第一个段落元素&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落元素&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;div&gt;我是一个块元素&lt;&#x2F;div&gt;</span><br><span class="line">&lt;&#x2F;div&gt;</span><br></pre></td></tr></table></figure>

<p>CSS代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">.wrapper &#123;</span><br><span class="line">  width: 500px;</span><br><span class="line">  margin: 20px auto;</span><br><span class="line">  padding: 10px;</span><br><span class="line">  border: 1px solid #ccc;</span><br><span class="line">  color: #fff;</span><br><span class="line">&#125;</span><br><span class="line">.wrapper &gt; div &#123;</span><br><span class="line">  background: green;</span><br><span class="line">&#125;</span><br><span class="line">.wrapper &gt; p &#123;</span><br><span class="line">  background: blue;</span><br><span class="line">&#125;</span><br><span class="line">&#x2F;*我要改变第一个段落的背景为橙色*&#x2F;</span><br><span class="line">.wrapper &gt; p:first-of-type &#123;</span><br><span class="line">  background: orange;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>演示结果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-469c4c40e381cd36.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h2 id="nth-of-type-n-选择器"><a href="#nth-of-type-n-选择器" class="headerlink" title="nth-of-type(n)选择器"></a>nth-of-type(n)选择器</h2><p>“<code>:nth-of-type(n)</code>”选择器和“<code>:nth-child(n)</code>”选择器非常类似，不同的是它只计算父元素中指定的某种类型的子元素。当某个元素中的子元素不单单是同一种类型的子元素时，使用“:nth-of-type(n)”选择器来定位于父元素中某种类型的子元素是非常方便和有用的。在“:nth-of-type(n)”选择器中的“n”和“:nth-child(n)”选择器中的“n”参数也一样，可以是具体的<strong>整数</strong>，也可以是表达式，还可以是<strong>关键词</strong>。</p>
<p>示例演示</p>
<p>通过“:nth-of-type(2n)”选择器，将容器“div.wrapper”中偶数段数的背景设置为橙色。</p>
<p>HTML代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">&lt;div class&#x3D;&quot;wrapper&quot;&gt;</span><br><span class="line">  &lt;div&gt;我是一个Div元素&lt;&#x2F;div&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落元素&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;div&gt;我是一个Div元素&lt;&#x2F;div&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;div&gt;我是一个Div元素&lt;&#x2F;div&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;div&gt;我是一个Div元素&lt;&#x2F;div&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;div&gt;我是一个Div元素&lt;&#x2F;div&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;div&gt;我是一个Div元素&lt;&#x2F;div&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;div&gt;我是一个Div元素&lt;&#x2F;div&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;div&gt;我是一个Div元素&lt;&#x2F;div&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落&lt;&#x2F;p&gt;</span><br><span class="line">&lt;&#x2F;div&gt;</span><br></pre></td></tr></table></figure>

<p>CSS代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">.wrapper &gt; p:nth-of-type(2n)&#123;</span><br><span class="line">  background: orange;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>演示结果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-aae61f3c635b9986.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h2 id="last-of-type选择器"><a href="#last-of-type选择器" class="headerlink" title="last-of-type选择器"></a>last-of-type选择器</h2><p>“<code>:last-of-type</code>”选择器和“<code>:first-of-type</code>”选择器功能是一样的，不同的是他选择是父元素下的某个类型的<strong>最后一个子元素</strong>。</p>
<p>示例演示</p>
<p>通过“<code>:last-of-type</code>”选择器，将容器“<code>div.wrapper</code>”中最后一个段落元素背景设置为橙色</p>
<p>（提示：这个段落不是“div.wrapper”容器的最后一个子元素）。</p>
<p>HTML代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&lt;div class&#x3D;&quot;wrapper&quot;&gt;</span><br><span class="line">  &lt;p&gt;我是第一个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;p&gt;我是第二个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;p&gt;我是第三个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;div&gt;我是第一个Div元素&lt;&#x2F;div&gt;</span><br><span class="line">  &lt;div&gt;我是第二个Div元素&lt;&#x2F;div&gt;</span><br><span class="line">  &lt;div&gt;我是第三个Div元素&lt;&#x2F;div&gt;</span><br><span class="line">&lt;&#x2F;div&gt;</span><br></pre></td></tr></table></figure>

<p>CSS代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"> .wrapper &gt; p:last-of-type&#123;</span><br><span class="line">  background: orange;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>演示结果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-68e808c4be24431f.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h2 id="nth-last-of-type-n-选择器"><a href="#nth-last-of-type-n-选择器" class="headerlink" title="nth-last-of-type(n)选择器"></a>nth-last-of-type(n)选择器</h2><p>“<code>:nth-last-of-type(n)</code>”选择器和“<code>:nth-of-type(n)</code>”选择器是一样的，选择父元素中指定的某种子元素类型，但它的起始方向是从最后一个子元素开始，而且它的使用方法类似于上节中介绍的“<code>:nth-last-child(n)</code>”选择器一样。</p>
<p>示例演示</p>
<p>通过“<code>:nth-last-of-type(n)</code>”选择器将容器“<code>div.wrapper</code>”中的倒数第三个段落背景设置为橙色。</p>
<p>HTML代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">&lt;div class&#x3D;&quot;wrapper&quot;&gt;</span><br><span class="line">  &lt;p&gt;我是第一个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;p&gt;我是第二个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;p&gt;我是第三个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;p&gt;我是第四个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;p&gt;我是第五个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;div&gt;我是一个Div元素&lt;&#x2F;div&gt;</span><br><span class="line">  &lt;p&gt;我是第六个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;p&gt;我是第七个段落&lt;&#x2F;p&gt;</span><br><span class="line">&lt;&#x2F;div&gt;</span><br></pre></td></tr></table></figure>

<p>CSS代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">.wrapper &gt; p:nth-last-of-type(3)&#123;</span><br><span class="line">  background: orange;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>演示结果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-a5bc41b6150ebd65.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h2 id="only-child选择器"><a href="#only-child选择器" class="headerlink" title="only-child选择器"></a>only-child选择器</h2><p>“<code>:only-child</code>”选择器选择的是父元素中只有一个子元素，而且只有唯一的一个子元素。也就是说，匹配的元素的父元素中仅有一个子元素，而且是一个<strong>唯一的子元素</strong>。</p>
<p>示例演示</p>
<p>通过“:only-child”选择器，来控制仅有一个子元素的背景样式，为了更好的理解，我们这个示例通过对比的方式来向大家演示。</p>
<p>HTML代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&lt;div class&#x3D;&quot;post&quot;&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落&lt;&#x2F;p&gt;</span><br><span class="line">&lt;&#x2F;div&gt;</span><br><span class="line">&lt;div class&#x3D;&quot;post&quot;&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落&lt;&#x2F;p&gt;</span><br><span class="line">&lt;&#x2F;div&gt;</span><br></pre></td></tr></table></figure>

<p>CSS代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">.post p &#123;</span><br><span class="line">  background: green;</span><br><span class="line">  color: #fff;</span><br><span class="line">  padding: 10px;</span><br><span class="line">&#125;</span><br><span class="line">.post p:only-child &#123;</span><br><span class="line">  background: orange;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>演示结果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-4b2cef7e4ef272d2.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<h2 id="only-of-type选择器"><a href="#only-of-type选择器" class="headerlink" title="only-of-type选择器"></a>only-of-type选择器</h2><p>“<code>:only-of-type</code>”选择器用来选择一个元素是它的父元素的唯一一个相同类型的子元素。这样说或许不太好理解，换一种说法。“<code>:only-of-type</code>”是表示一个元素他有很多个子元素，而其中只有一种类型的子元素是唯一的，使用“<code>:only-of-type</code>”选择器就可以选中这个元素中的唯一一个类型子元素。</p>
<p>示例演示</p>
<p>通过“<code>:only-of-type</code>”选择器来修改容器中仅有一个div元素的背景色为橙色。</p>
<p>HTML代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&lt;div class&#x3D;&quot;wrapper&quot;&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落&lt;&#x2F;p&gt;</span><br><span class="line">  &lt;div&gt;我是一个Div元素&lt;&#x2F;div&gt;</span><br><span class="line">&lt;&#x2F;div&gt;</span><br><span class="line">&lt;div class&#x3D;&quot;wrapper&quot;&gt;</span><br><span class="line">  &lt;div&gt;我是一个Div&lt;&#x2F;div&gt;</span><br><span class="line">  &lt;ul&gt;</span><br><span class="line">    &lt;li&gt;我是一个列表项&lt;&#x2F;li&gt;</span><br><span class="line">  &lt;&#x2F;ul&gt;</span><br><span class="line">  &lt;p&gt;我是一个段落&lt;&#x2F;p&gt;</span><br><span class="line">&lt;&#x2F;div&gt;</span><br></pre></td></tr></table></figure>

<p>CSS代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">.wrapper &gt; div:only-of-type &#123;</span><br><span class="line">  background: orange;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>演示结果：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-15b9942d264233ac.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/CSS%E9%A2%9D%E5%A4%96%E7%9F%A5%E8%AF%86%E7%82%B9-%E9%A2%9C%E8%89%B2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/CSS%E9%A2%9D%E5%A4%96%E7%9F%A5%E8%AF%86%E7%82%B9-%E9%A2%9C%E8%89%B2/" class="post-title-link" itemprop="url">CSS额外知识点--颜色</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 14:36:00 / Modified: 14:36:16" itemprop="dateCreated datePublished" datetime="2020-08-26T14:36:00+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/CSS/" itemprop="url" rel="index"><span itemprop="name">CSS</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="颜色之RGBA"><a href="#颜色之RGBA" class="headerlink" title="颜色之RGBA"></a>颜色之RGBA</h2><p>RGB是一种色彩标准，是由红(R)、绿(G)、蓝(B)的变化以及相互叠加来得到各式各样的颜色。RGBA是在RGB的基础上增加了控制alpha透明度的参数。</p>
<p>语法：</p>
<p><code>color：rgba(R,G,B,A)</code></p>
<p>以上R、G、B三个参数，正整数值的取值范围为：0 - 255。百分数值的取值范围为：0.0% - 100.0%。超出范围的数值将被截至其最接近的取值极限。并非所有浏览器都支持使用百分数值。A为透明度参数，取值在0~1之间，不可为负值。</p>
<p>代码示例：</p>
<p><code>background-color:rgba(100,120,60,0.5);</code></p>
<h2 id="渐变色彩"><a href="#渐变色彩" class="headerlink" title="渐变色彩"></a>渐变色彩</h2><p>CSS3 Gradient 分为线性渐变(linear)和径向渐变(radial)。由于不同的渲染引擎实现渐变的语法不同，这里我们只针对线性渐变的 W3C 标准语法来分析其用法，其余大家可以查阅相关资料。W3C 语法已经得到了 IE10+、Firefox19.0+、Chrome26.0+ 和 Opera12.1+等浏览器的支持。</p>
<p>这一小节我们来说一下线性渐变：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-9c99e85c7a8a46fd.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>参数：</p>
<p>第一个参数:指定<strong>渐变方向</strong>，可以用“<strong>角度</strong>”的关键词或“<strong>英文</strong>”来表示：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-d9fd5886208fdc86.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>（单击图片可放大）</p>
<p>第一个参数省略时，默认为“180deg”，等同于“to bottom”。</p>
<p>第二个和第三个参数，表示<strong>颜色的起始点和结束点</strong>，可以有多个颜色值。</p>
<p><code>background-image:linear-gradient(to left, red, orange,yellow,green,blue,indigo,violet);</code></p>
<p>效果图：</p>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-91d9e492b8ec5bce.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/CSS%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E7%82%B9/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/CSS%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86%E7%82%B9/" class="post-title-link" itemprop="url">CSS基础知识点</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 14:35:10 / Modified: 14:35:31" itemprop="dateCreated datePublished" datetime="2020-08-26T14:35:10+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/CSS/" itemprop="url" rel="index"><span itemprop="name">CSS</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="HTML、CSS、JavaScript关系"><a href="#HTML、CSS、JavaScript关系" class="headerlink" title="HTML、CSS、JavaScript关系"></a>HTML、CSS、JavaScript关系</h2><ul>
<li><p>HTML是网页内容的载体</p>
</li>
<li><p>CSS样式是表现（外观控制）</p>
</li>
<li><p>JavaScript是行为，用来实现网页特效效果</p>
</li>
</ul>
<h2 id="CSS导入式"><a href="#CSS导入式" class="headerlink" title="CSS导入式"></a>CSS导入式</h2><ul>
<li><p>@import “外部CSS样式”</p>
</li>
<li><p>@import url(外部CSS样式)</p>
</li>
</ul>
<h2 id="CSS使用方法区别"><a href="#CSS使用方法区别" class="headerlink" title="CSS使用方法区别"></a>CSS使用方法区别</h2><table>
<thead>
<tr>
<th>类别</th>
<th>引入方法</th>
<th>位置</th>
<th>加载</th>
</tr>
</thead>
<tbody><tr>
<td>行内样式</td>
<td>开始标签内的style</td>
<td>html文件内</td>
<td>同时</td>
</tr>
<tr>
<td>内部样式</td>
<td><code>&lt;head&gt;</code>中<code>&lt;style&gt;</code>内</td>
<td>html文件内</td>
<td>同时</td>
</tr>
<tr>
<td>链入外部样式</td>
<td><code>&lt;head&gt;</code>中<code>&lt;link&gt;</code>引用</td>
<td>CSS样式文件与html文件分离</td>
<td>页面加载时，同时加载CSS样式</td>
</tr>
<tr>
<td>导入式@import</td>
<td>在样式代码最开始处</td>
<td>CSS样式文件与html文件分离</td>
<td>在读取完html文件之后加载</td>
</tr>
</tbody></table>
<h3 id="使用链入外部样式的好处"><a href="#使用链入外部样式的好处" class="headerlink" title="使用链入外部样式的好处"></a>使用链入外部样式的好处</h3><ol>
<li><p>CSS和HTML分离</p>
</li>
<li><p>多个文件可以使用同一个样式文件</p>
</li>
<li><p>多文件引用同一个CSS文件，CSS只需下载一次</p>
</li>
</ol>
<h3 id="CSS使用方法优先级"><a href="#CSS使用方法优先级" class="headerlink" title="CSS使用方法优先级"></a>CSS使用方法优先级</h3><blockquote>
<p>行内样式&gt;内部样式&gt;外部样式</p>
</blockquote>
<p>说明：</p>
<ol>
<li><p>链入外部样式表与内部样式表之间的优先级取决于所处位置的先后</p>
</li>
<li><p>根据样式与元素的距离而定，越接近优先级就越高（就近原则）</p>
</li>
</ol>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/hexo/page/8/"><i class="fa fa-angle-left" aria-label="Previous page"></i></a><a class="page-number" href="/hexo/">1</a><span class="space">&hellip;</span><a class="page-number" href="/hexo/page/8/">8</a><span class="page-number current">9</span><a class="page-number" href="/hexo/page/10/">10</a><span class="space">&hellip;</span><a class="page-number" href="/hexo/page/13/">13</a><a class="extend next" rel="next" href="/hexo/page/10/"><i class="fa fa-angle-right" aria-label="Next page"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="幽辰"
      src="/hexo/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">幽辰</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/hexo/archives/">
        
          <span class="site-state-item-count">127</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/hexo/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/hexo/tags/">
          
        <span class="site-state-item-count">23</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">幽辰</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a>
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/hexo/lib/anime.min.js"></script>
  <script src="/hexo/lib/velocity/velocity.min.js"></script>
  <script src="/hexo/lib/velocity/velocity.ui.min.js"></script>

<script src="/hexo/js/utils.js"></script>

<script src="/hexo/js/motion.js"></script>


<script src="/hexo/js/schemes/pisces.js"></script>


<script src="/hexo/js/next-boot.js"></script>




  















  

  

</body>
</html>
